<?php
class ControllerManagementPage extends Controller {
	private $error = array();
	
	public function index() {
		$this->document->setTitle('网站内容管理');
		
		$this->children = array(
				'common/header',
				'common/footer'
				);
		//$this->load->model('management/page');
		$this->getList();
	}
	
	public function insert(){
		$this->document->setTitle('创建新页面');

		$this->getForm();
	}
	
	public function getList(){
		$this->data['breadcrumbs'] = array();
		
		$this->data['breadcrumbs'][] = array(
			'text'		=> '首页',
			'href'		=> $this->url->link('common/home','token='.$this->session->data['token'],'SSL'),
			'separator'	=> false
		);
		
		$this->data['breadcrumbs'][] = array(
			'text'		=> '网站内容管理',
			'href'		=> $this->getTokenUrl('management/page'),
			'separator'	=> ' :: '
		);
		
		$this->data['insert'] = $this->getTokenUrl('management/page/insert');
		$this->data['delete'] = $this->getTokenUrl('management/page/delete');
		
		$this->data['pages'] = array();
		
		$this->template = 'management/page_list.tpl';
		
		$this->children = array(
			'common/header',
			'common/footer'
		);
		
		$this->response->setOutput($this->render());
	}
	
	public function getForm(){
		
		
		$this->data['breadcrumbs'] = array();
		
		$this->data['breadcrumbs'][] = array(
				'text'		=> '首页',
				'href'		=> $this->url->link('common/home','token='.$this->session->data['token'],'SSL'),
				'separator'	=> false
		);
		
		$this->data['breadcrumbs'][] = array(
				'text'		=> '网站内容管理',
				'href'		=> $this->getTokenUrl('management/page'),
				'separator'	=> ' :: '
		);
		
		if(isset($this->error['warning'])) {
			$this->data['error_warning'] = $this->error['warning'];
		} else {
			$this->data['error_warning'] = '';
		}
		
		$this->load->model('localisation/language');
		$this->data['languages'] = $this->model_localisation_language->getLanguages();
		
		
		
		
		$this->template = 'management/page_form.tpl';
		
		$this->children = array(
				'common/header',
				'common/footer'
		);
		
		$this->response->setOutput($this->render());

	}
	
	private function getTokenUrl($route) {
		$token_url = $this->url->link($route, 'token=' . $this->session->data['token'], 'SSL');
		return $token_url;
	}
}

?>